//
//  WKAttentionItemCell.m
//  WuKongUsernameLogin
//
//  Created by tt on 2023/9/9.
//

#import "WKAttentionItemCell.h"

@implementation WKAttentionItemModel

- (Class)cell {
    return  WKAttentionItemCell.class;
}


@end

@interface WKAttentionItemCell ()

@property(nonatomic,strong) UIView *itemView;

@property(nonatomic,strong) UILabel *itemLbl;

@property(nonatomic,strong) WKCheckBox *checkBox;

@property(nonatomic,strong) WKAttentionItemModel *model;

@end

@implementation WKAttentionItemCell


- (void)setupUI {
    [super setupUI];
    self.backgroundColor = [UIColor clearColor];
    self.contentView.backgroundColor = [UIColor clearColor];
    [self.contentView addSubview:self.itemView];
    
    [self.itemView addSubview:self.itemLbl];
    [self.itemView addSubview:self.checkBox];
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onItemView)];
    [self.itemView addGestureRecognizer:tap];
}

- (void)refresh:(WKAttentionItemModel *)model {
    [super refresh:model];
    self.model = model;
    self.itemLbl.text = model.content;
}

-(void) onItemView {
    [self.checkBox setOn:!self.checkBox.on];
    if(self.model.onCheck) {
        self.model.onCheck(self.checkBox.on);
    }
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
   
    
    self.itemView.lim_width = self.lim_width - 40.0f;
    self.itemView.lim_height = self.lim_height;
    self.itemView.lim_left = 20.0f;
    
    self.itemLbl.lim_height = self.lim_height;
    self.itemLbl.lim_left = 10.0f;
    
    self.itemLbl.lim_width = self.lim_width - 110.0f;
    
    self.checkBox.lim_left = self.itemView.lim_width - self.checkBox.lim_width - 10.0f;
    self.checkBox.lim_centerY_parent = self;
    
   
}

- (UIView *)itemView {
    if(!_itemView) {
        _itemView = [[UIView alloc] init];
        _itemView.layer.masksToBounds = YES;
        _itemView.layer.borderColor = WKApp.shared.config.lineColor.CGColor;
        _itemView.layer.borderWidth = 1.0f;
        _itemView.layer.cornerRadius = 8.0f;
    }
    return _itemView;
}

- (UILabel *)itemLbl {
    if(!_itemLbl) {
        _itemLbl = [[UILabel alloc] init];
        _itemLbl.lineBreakMode = NSLineBreakByTruncatingTail;
        _itemLbl.numberOfLines = 0;
        _itemLbl.textColor = WKApp.shared.config.tipColor;
//        _itemLbl.textAlignment = NSTextAlignmentJustified;
        _itemLbl.font =  [WKApp.shared.config appFontOfSize:15.0f];
    }
    return _itemLbl;
}

- (WKCheckBox *)checkBox {
    if(!_checkBox) {
        _checkBox = [[WKCheckBox alloc] initWithFrame:CGRectMake(0, 0, 24.0f, 24.0f)];
        _checkBox.onFillColor = [WKApp shared].config.themeColor;
        _checkBox.onCheckColor = [UIColor whiteColor];
        _checkBox.onTintColor = [WKApp shared].config.themeColor;
        _checkBox.onAnimationType = BEMAnimationTypeBounce;
        _checkBox.offAnimationType = BEMAnimationTypeBounce;
        _checkBox.animationDuration = 0.0f;
        _checkBox.lineWidth = 1.0f;
    }
    return _checkBox;
}


@end
